import { getSignature } from '@/api/shop';
//#ifdef H5
import wxsdk from 'weixin-js-sdk';
//#endif
export function configWeiXin(callback) {
    //懂点前端应该知道这里是查询接口的箭头函数，内部细节不写了，就是查询后端返回的公众号参数信息

    getSignature({ shareUrl: encodeURI(window.location.origin) })
        .then((result) => {
            let apiList = [
                // 可能需要用到的能力 需要啥就写啥。多写也没有坏处
                'onMenuShareAppMessage',
                'onMenuShareTimeline',
                'hideOptionMenu',
                'showOptionMenu',
                'chooseWXPay',
                'checkJsApi',
                'openLocation',
                'getLocation',
            ];
            let info = {
                debug: false, // 调试，发布的时候改为false
                appId: result.appId,
                nonceStr: result.nonceStr,
                timestamp: result.timestamp,
                signature: result.signature,
                jsApiList: apiList,
            };
            console.log(info);
            wxsdk.config(info);
            wxsdk.error((err) => {
                console.log('config fail:', err);
            });

            wxsdk.ready((res) => {
                if (callback) callback(wxsdk);
            });
        })
        .catch();
}
